package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.WaitProductBean;
import com.project.dto.WaitProductDto;
import com.project.dto.WaitProductDtoWeb;
import com.project.service.IWaitProductServiceRE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("waitProduct")
public class WaitProductController {
    @Autowired
    private IWaitProductServiceRE waitProductService;
    @RequestMapping("findWaitProduct")
    public IPage<WaitProductDto> findWaitProduct(int pageNO,String productType,Integer productStatus){
        return waitProductService.findWaitProduct(pageNO,productType,productStatus);
    }
    /**
     * 根据订单中的商品，减少待上架商品的数量，当订单状态为完成时调用
     * @param orderNum  订单编号
     * @return 是否修改成功
     */
    @RequestMapping("updateWaitProductNumByOrderInfo")
    Boolean updateWaitProductNumByOrderInfo(String orderNum){
        return waitProductService.updateWaitProductNumByOrderInfo(orderNum);
    }

    /**
     * 查找待上架商品
     * 前端添加到美化商品中时调用
     * @param type  商品类型
     * @param name  商品名字
     * @return  返回待上架商品对象集合
     */
    @RequestMapping("/findWaitProductByTypeAndName/{type}/{name}")
    List<WaitProductDtoWeb> findWaitProductByTypeAndName(@PathVariable("type") String type, @PathVariable("name") String name){
        System.out.println("ok");
        return waitProductService.findWaitProductByTypeAndName(type, name);
    }
}
